<?php
/**
 * 
 */

/**
 * This function is responsible for displaying the "Primary Navigation" bar.
 *
 * @uses genesis_nav(), genesis_get_option()
 * @since 1.0
 */
add_action('genesis_after_header', 'genesis_do_nav');
function genesis_do_nav() {
	if( genesis_get_option('nav') ) {
		$args = array(
			'context' => 'nav',
			'menu_class' => genesis_get_option('nav_superfish') ? 'nav superfish' : 'nav',
			'show_home' => genesis_get_option('nav_home'),
			'type' => genesis_get_option('nav_type'),
			'sort_column' => genesis_get_option('nav_pages_sort'),
			'orderby' => genesis_get_option('nav_categories_sort'),
			'depth' => genesis_get_option('nav_depth'),
			'exclude' => genesis_get_option('nav_exclude'),
			'include' => genesis_get_option('nav_include'),
			'echo' => false
		);
		
		echo '<div id="nav"><div class="wrap">'.genesis_nav($args).'</div></div>';
	}
}

/**
 * This function  is responsible for displaying the "Secondary Navigation" bar.
 *
 * @uses genesis_nav(), genesis_get_option()
 * @since 1.0.1
 *
 */
add_action('genesis_after_header', 'genesis_do_subnav');
function genesis_do_subnav() {
	if( genesis_get_option('subnav') ) {
		$args = array(
			'context' => 'subnav',
			'menu_class' => genesis_get_option('subnav_superfish') ? 'nav superfish' : 'nav',
			'show_home' => genesis_get_option('subnav_home'),
			'type' => genesis_get_option('subnav_type'),
			'sort_column' => genesis_get_option('subnav_pages_sort'),
			'orderby' => genesis_get_option('subnav_categories_sort'),
			'depth' => genesis_get_option('subnav_depth'),
			'exclude' => genesis_get_option('subnav_exclude'),
			'include' => genesis_get_option('subnav_include'),
			'echo' => false
		);
		
		echo '<div id="subnav"><div class="wrap">'.genesis_nav($args).'</div></div>';
	}
}

/**
 * This function filters the Primary Navigation menu items, appending
 * either RSS links, search form, twitter link, or today's date.
 *
 * @uses genesis_get_option(), get_bloginfo(), get_search_form(),
 * @since 1.0
 */
add_filter('genesis_nav_items', 'genesis_nav_right', 10, 2);
function genesis_nav_right($menu, $args) {
	
	if( !genesis_get_option('nav_extras_enable') || $args['context'] != 'nav' )
		return $menu;
	
	if( genesis_get_option('nav_extras') == 'rss' ) {
		$rss = '<a rel="nofollow" href="'.get_bloginfo('rss_url').'">'.__('Posts', 'genesis').'</a>';
		$rss .= '<a rel="nofollow" href="'.get_bloginfo('comments_rss2_url').'">'.__('Comments', 'genesis').'</a>';
		
		$menu .= '<li class="right rss">'.$rss.'</li>';
	}
	elseif( genesis_get_option('nav_extras') == 'search' ) {
		// I hate output buffering, but I have no choice
		ob_start();
		get_search_form();
		$search = ob_get_clean();
		
		$menu .= '<li class="right search">'.$search.'</li>';
	}
	elseif( genesis_get_option('nav_extras') == 'twitter' ) {
		$twitter = '<a href="' . esc_url( 'http://twitter.com/'.genesis_get_option('nav_extras_twitter_id') ) .'">'.genesis_get_option('nav_extras_twitter_text').'</a>';
		
		$menu .= '<li class="right twitter">'.$twitter.'</li>';
	}
	elseif( genesis_get_option('nav_extras') == 'date' ) {
		$menu .= '<li class="right date">'.date_i18n(get_option('date_format')).'</li>';
	}
	
	return $menu;
	
}